package com.usian.jyzx.product.service.impl;

import com.usian.jyzx.model.entity.product.Brand;
import com.usian.jyzx.model.entity.product.Category;
import com.usian.jyzx.model.entity.product.Product;
import com.usian.jyzx.product.mapper.BrandMapper;
import com.usian.jyzx.product.mapper.CategoryMapper;
import com.usian.jyzx.product.mapper.ProductMapper;
import com.usian.jyzx.product.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @TODO:
 * @Author:baimu
 * @Date:2024 07 08 14 20
 **/
@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    ProductMapper productMapper;
    @Autowired
    BrandMapper brandMapper;

   @Autowired
   CategoryMapper categoryMapper;
    @Override
    public Product findProductById(Long id) {
        Product product = productMapper.findProductById(id);
        Brand brand = brandMapper.findByBrandId(product.getBrandId());
        product.setBrandName(brand.getName());

        Category category1 = categoryMapper.findById(product.getCategory1Id());
        product.setCategory1Name(category1.getName());
        Category category2 = categoryMapper.findById(product.getCategory2Id());
        product.setCategory2Name(category2.getName());

        Category category3 = categoryMapper.findById(product.getCategory3Id());
        product.setCategory3Name(category3.getName());
        return product;
    }
}
